const path = require('path');
const CopyPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const ZipWebpackPlugin = require('zip-webpack-plugin')

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
      {
        test: /\.jpg|\.png|\.jpeg|\.svg|\.ttf|\.woff$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 5000,
              esModule: false,
              name: '[name][hash:8].[ext]',
              outputPath: 'images/'
            }
          }
        ]
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      title: '我是首页的标题',
      meta: {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'},
      favicon: 'public/favicon.ico',
      template: 'public/index.html'
    }),
    new CopyPlugin([
      { from: './public',to: './' }
    ]),
    new ZipWebpackPlugin ({
      path:path.join(__dirname,'./dist'),
      filename: 'bhg-member-portal.zip'
    })
  ],
  watch: false,   // 监听文件改动并自动打包
  devServer: {
    static: {
      directory: path.join(__dirname, 'public'),
    },
    compress: true,
    port: 9001,
  },
  mode: 'development'
};